package com.kg.fiber.service.security;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import com.ivan.toolkit.common.Configs;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
@NoArgsConstructor
public class SecurityConfig {
	
	
	public static Configs.Instance<SecurityConfig> instance = 
			new Configs.Instance<SecurityConfig>(SecurityConfig.class);	
	
	public static PasswordEncoder encoder = new BCryptPasswordEncoder(4);
	
	/**
	 * 用于进入配置界面的登陆密码
	 */
	@XmlAttribute
	@Setter @Getter
	private String accessPassword = encoder.encode("admin");
		
	
	public void setNewPassword(String password) {
		
		accessPassword = encoder.encode(password);
		
	}
	
	public boolean checkPassword(String password) {
		
		return encoder.matches(password, accessPassword);
		
	}
	
}
